Vue.filter('formatIcon',function (value) {
    var code;
    switch (parseInt(value)){
        case 100://晴
            return "#icon-qingtian";
        case 104://阴
            return "#icon-yintian";
        case 101://多云
        case 102://少云
        case 103://晴间多云
            return "#icon-duoyun";
        case 305://小雨
        case 309://毛毛雨
        case 306://中雨
            return "#icon-xiaoyu";
        case 307://大雨
            return "#icon-tedaleizhenyu";
        case 300://阵雨
        case 301://强阵雨
        case 302://雷阵雨
        case 303://强雷阵雨
            return "#icon-zhenyu";
        case 304://雷阵雨伴有冰雹
        case 313://冻雨
            return "icon-icon-test6";
        case 308://极端降雨
        case 311://大暴雨
        case 312://特大暴雨
            return "#icon-yujiaxue";
        case 310://暴雨
            return "#icon-baoyu";
        case 400://小雪
        case 407://阵雪
        case 401://中雪
            return "#icon-zhongxue";
        case 402://大雪
            return "#icon-baoxue";
        case 404://雨夹雪
        case 405://雨夹雪
        case 406://雨夹雪
            return "#icon-yujiaxue";
        case 503://扬沙
            return "#icon-yangsha";
        case 504://浮沉
            return "#icon-fuchen";
        case 507://沙尘暴
        case 508://强沙尘暴
            return "#icon-tedayangsha";
        case 403://暴雪
            return "#icon-baoxue";
        case 500://薄雾
        case 501://雾
            return "#icon-wu";
        case 502://霾
            return "#icon-wu";
        case 208://烈风
        case 209://风暴
        case 210://狂爆风
        case 211://飓风
            return "icon-icon-test18";
        case 205://强风/劲风
            return "#icon-icon-test";
        case 206://疾风
        case 207://大风
            return "#icon-icon-test1";
        case 212://龙卷风
        case 213://热带风暴
            return "#icon-icon-test2";
        case 200://有风
        case 201://平静
        case 202://微风
        case 203://和风
        case 204://清风
            return "#icon-icon-test3";
        default:
            return "#icon-icon-test4";
    }
});
var vm = new Vue({
    el:"#app",
    data:{
        API_WEATHER:"https://free-api.heweather.com/s6/weather",
        API_NOW:"https://free-api.heweather.com/s6/weather/now",
        API_HOURLY:"https://free-api.heweather.com/s6/weather/hourly",
        API_DAILY_FORECAST:"https://free-api.heweather.com/s6/weather/forecast",
        API_LIFESTYLE:"https://free-api.heweather.com/s6/weather/lifestyle",
        parameters:{key:"92dab76901534ea4b70d605a77835d37",location:"济宁"},
        basic:{},
        update:"",
        now:{},
        hourly:[],
        daily_forecast:[],
        lifestyle:[]
    },
    filters:{
        formatTemp:function (value) {
            return value+"℃";
        },
        formatTime:function (value) {
            return value.substring(11,13)+'h';
        },
        formatDate:function (value) {
            return value.substring(5);
        },
        formatLifeStyle:function (value) {
            switch (value){
                case "comf":
                    return "舒适度指数";
                case "drsg":
                    return "穿衣指数";
                case "flu":
                    return "感冒指数";
                case "sport":
                    return "运动指数";
                case "trav":
                    return "旅游指数";
                case "uv":
                    return "紫外线指数";
                case "cw":
                    return "洗车指数";
                case "air":
                    return "空气质量";
            }
        }
    },
    mounted:function () {
        var _this = this;
        this.$nextTick(function () {
            _this.loadWeather("济宁");
        });
    },
    methods:{
        loadWeather:function (city) {
            this.parameters.location = city;
            var _this = this;
            this.$http.get(this.API_WEATHER,this.parameters).then(function (res) {
                var data = res.data.HeWeather6[0];
                if(data.status === "ok"){
                    _this.basic = data.basic;
                    _this.update = data.update.loc;
                    _this.now = data.now;
                    _this.hourly = data.hourly;
                    _this.daily_forecast = data.daily_forecast;
                    _this.lifestyle = data.lifestyle;
                }else {
                    alert(data.status);
                }
            });
        },
        changeCity:function () {
            var city = $("input").val();
            this.loadWeather(city);
        }
    }
});